﻿Imports System.Collections.Generic
Imports System.Data
Imports System.Data.SqlClient


''' <summary>
''' Clase de la capa de acceso a datos DAL que implementa el patrón Table Data Gateway para el manejo de la entidad Bitacora
''' </summary>
''' <remarks></remarks>
Public Class TDGBitacora

    Private Shared m_Instance As TDGBitacora = Nothing


    Public Function Insert(conn As SqlConnection, Usu_Legajo As Int16, Oper_Codigo As Int16) As Int16
        Dim command As New SqlCommand
        Dim iRowsAffected As Int16

        command.Connection = conn
        command.CommandType = CommandType.StoredProcedure

        command.CommandText = "dbo.addBitacora_Usuario"
        command.Parameters.AddWithValue("@Usu_Legajo", Usu_Legajo)
        command.Parameters.AddWithValue("@Oper_Codigo", Oper_Codigo)


        iRowsAffected = command.ExecuteNonQuery()


        Return iRowsAffected

    End Function

    Public Function FindByUser(conn As SqlConnection, Usu_Legajo As Int16) As SqlDataReader
        Dim command As New SqlCommand
        Dim dr As SqlDataReader


        command.Connection = conn
        command.CommandType = CommandType.StoredProcedure

        command.CommandText = "dbo.getBitacora_Usuario"
        command.Parameters.AddWithValue("@Usu_Legajo", Usu_Legajo)


        dr = command.ExecuteReader()

        Return dr

    End Function

    Public Function FindAll(conn As SqlConnection) As SqlDataReader
        Dim command As New SqlCommand
        Dim dr As SqlDataReader

        command.Connection = conn
        command.CommandType = CommandType.StoredProcedure

        command.CommandText = "dbo.getBitacora_Usuario_All"


        dr = command.ExecuteReader()

        Return dr

    End Function

    Public Function FindHoy(conn As SqlConnection) As SqlDataReader
        Dim command As New SqlCommand
        Dim dr As SqlDataReader

        command.Connection = conn
        command.CommandType = CommandType.StoredProcedure

        command.CommandText = "dbo.getBitacora_Usuario_Hoy"


        dr = command.ExecuteReader()

        Return dr

    End Function

    Public Function FindAyer(conn As SqlConnection) As SqlDataReader
        Dim command As New SqlCommand
        Dim dr As SqlDataReader

        command.Connection = conn
        command.CommandType = CommandType.StoredProcedure

        command.CommandText = "dbo.getBitacora_Usuario_Ayer"


        dr = command.ExecuteReader()

        Return dr

    End Function

    Public Function Find7dias(conn As SqlConnection) As SqlDataReader
        Dim command As New SqlCommand
        Dim dr As SqlDataReader

        command.Connection = conn
        command.CommandType = CommandType.StoredProcedure

        command.CommandText = "dbo.getBitacora_Usuario_7dias"


        dr = command.ExecuteReader()

        Return dr

    End Function

    Public Function Find30dias(conn As SqlConnection) As SqlDataReader
        Dim command As New SqlCommand
        Dim dr As SqlDataReader

        command.Connection = conn
        command.CommandType = CommandType.StoredProcedure

        command.CommandText = "dbo.getBitacora_Usuario_30dias"


        dr = command.ExecuteReader()

        Return dr

    End Function

    Public Shared ReadOnly Property Instance()
        Get
            If (m_Instance Is Nothing) Then
                m_Instance = New TDGBitacora()
            End If

            Return m_Instance
        End Get
    End Property

    Private Sub New()

    End Sub

End Class
